﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Communergy.Repository;
using Communergy.UnitTesting;
using Communergy.Common;
using Communergy.Repository.EntityFramework;


namespace CommunergyLogicTests
{
    public class CommunergyTestHelper
    {
        public static ElectricityMeter GetRandomMeter()
        {
            communergyEntities db = new communergyEntities();
            var meterGuid = Guid.NewGuid();

            var newMeter = new ElectricityMeter
            {
                me_meterGuid = meterGuid,
                me_meterName = UnitTestHelper.RandomString(15)
            };
            db.AddToElectricityMeter(newMeter);
            db.SaveChanges();
            return newMeter;
        }




        public static List<RealtimeEnergyReading> CreateRealtimeRecords(int recordsToCreate, int interval, DateTime baseDateTime)
        {
            var newRealtimeEnergyReadings = new List<RealtimeEnergyReading>();

            for (int i = 0; i < recordsToCreate; i++)
            {
                RealtimeEnergyReading newReading = new RealtimeEnergyReading();
                var newReadingIntervalfromStart = i * 6;
                newReading.ReadingDateTime = baseDateTime.AddSeconds(newReadingIntervalfromStart);
                var reading = UnitTestHelper.RandomInt(100, 1000);
                newReading.Watts = reading;
                var joules = reading * interval;
                newReading.Joules = joules;

                newRealtimeEnergyReadings.Add(newReading);
            }
            return newRealtimeEnergyReadings;
        }

       
    }
}
